package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.core.domain.JsonResponse;
import com.ruoyi.system.domain.dto.TInterfaceDto;
import com.ruoyi.system.domain.po.TInterface;
import com.ruoyi.system.domain.po.TInterfaceCategory;
import com.ruoyi.system.domain.po.TInterfaceLog;
import com.ruoyi.system.domain.vo.TInterfaceCategoryVo;
import com.ruoyi.system.domain.vo.TInterfaceVo;
import com.ruoyi.system.service.TInterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nanyang
 */
@RestController
@RequestMapping("/interface")
@Api(tags = "接口、接口分类管理")
public class TInterfaceController {

    @Resource
    TInterfaceService interfaceService;


    @ApiOperation("新增接口")
    @PostMapping("/insertInterface")
    public JsonResponse insertInterface(@RequestBody @Validated TInterfaceDto.Insert interfaceInsert){
        return JsonResponse.ok(interfaceService.insertInterface(interfaceInsert));
    }

    @ApiOperation("修改接口")
    @PostMapping("/updateInterface")
    public JsonResponse updateInterface(@RequestBody @Validated TInterfaceDto.Update interfaceUpdate){
        return JsonResponse.ok(interfaceService.updateInterface(interfaceUpdate));
    }

    @ApiOperation("删除接口")
    @PostMapping("/deleteInterface")
    public JsonResponse deleteInterface(@RequestBody @Validated TInterfaceDto.Delete interfaceDelete){
        return JsonResponse.ok(interfaceService.deleteInterface(interfaceDelete));
    }

    @ApiOperation("查询接口列表")
    @PostMapping("/listInterface")
    public JsonResponse<PageInfo<TInterfaceVo.Result>> listInterface(@RequestBody @Validated BaseDto<TInterfaceDto.Query> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(interfaceService.listInterface(list.getParam())));
    }

    @ApiOperation("新增接口分类")
    @PostMapping("/insertCategory")
    public JsonResponse insertCategory(@RequestBody @Validated TInterfaceDto.CategoryInsert categoryInsert){
        return JsonResponse.ok(interfaceService.insertCategory(categoryInsert));
    }

    @ApiOperation("修改接口分类")
    @PostMapping("/updateCategory")
    public JsonResponse updateCategory(@RequestBody @Validated TInterfaceDto.CategoryUpdate categoryUpdate){
        return JsonResponse.ok(interfaceService.updateCategory(categoryUpdate));
    }

    @ApiOperation("删除接口分类")
    @PostMapping("/deleteCategory")
    public JsonResponse deleteCategory(@RequestBody @Validated TInterfaceDto.CategoryDelete categoryDelete){
        return JsonResponse.ok(interfaceService.deleteCategory(categoryDelete));
    }

    @ApiOperation("查询接口分类列表")
    @PostMapping("/listCategory")
    public JsonResponse<PageInfo<TInterfaceCategoryVo>> listCategory(@RequestBody @Validated BaseDto<TInterfaceDto.QueryCategory> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(interfaceService.listCategory(list.getParam())));
    }

    @ApiOperation("查询接口分类树形图")
    @PostMapping("/treeCategory")
    public JsonResponse<List<TInterfaceCategoryVo>> treeCategory(@RequestBody @Validated TInterfaceDto.TreeCategory treeCategory){
        return JsonResponse.ok(interfaceService.treeCategory(treeCategory));
    }

    @ApiOperation("查询接口日志")
    @PostMapping("/queryLog")
    public JsonResponse<PageInfo<TInterfaceLog>> queryLog(@RequestBody @Validated BaseDto<TInterfaceDto.LogQuery> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(interfaceService.queryLog(list.getParam())));
    }

}
